package com.study01.lesson04_URL;

import java.io.FileOutputStream;
import java.io.InputStream;
import java.net.HttpURLConnection;

import java.net.URL;


public class UrlDown {
    public static void main(String[] args) throws  Exception{

        URL url = new URL("https://valipl.cp31.ott.cibntv.net/67756D6080932713CFC02204E/05007C000060ADC5EC8BB7800000003EDBDEFD-97F8-483D-8936-5D18799FE02E_video_00001.mp4?ccode=0502&duration=6676&expire=18000&psid=3ffe0dd13824782e3a7f0d35e7acb50043346&ups_client_netip=ca77b3b5&ups_ts=1622712763&ups_userid=&apscid=&mnid=&umt=1&type=cmaf4hd&utid=sgcEGUGY6BYCATFKT0ItTVKx&vid=XNTE2MDQ1NDkyOA%3D%3D&s=dabe7d30c8064b3e9dab&sp=&t=e1cc9c2aefdcc57&cug=2&bc=2&si=5&eo=1&vkey=B8bea888659eab67a79e86a8e1e561f55");
        //2连接到这个资源
        HttpURLConnection urlConnection = ( HttpURLConnection) url.openConnection();

        InputStream inputStream = urlConnection.getInputStream();

        FileOutputStream fos =new FileOutputStream("f1.mp4");

        byte[] buffer = new byte[1024];
        int len;
        while((len=inputStream.read(buffer)) != -1){
            fos.write(buffer,0,len); //写出这个数据
        }

        fos.close();
        inputStream.close();
        urlConnection.disconnect();

    }
}
